@extends('layouts.app')
@section('title','订单列表')
@section('content')
  <div class="row">
    <div class="col-lg-10 offset-lg-1">
      <div class="card">
        <div class="card-header">订单列表</div>
        <div class="card-body">
          <ul class="list-group">
            @foreach($orders as $order)
              <li class="list-group-item">
                <div class="card">
                  <div class="card-header">
                    订单号：{{$order->no}}
                    <span class="float-right">{{$order->created_at->format('Y:m:d H:i:s')}}</span>
                  </div>
                  <div class="card-body">
                    <table class="table">
                      <thead>
                      <tr>
                        <th>商品信息</th>
                        <th class="text-center">单价</th>
                        <th class="text-center">数量</th>
                        <th class="text-center">订单总价</th>
                        <th class="text-center">状态</th>
                        <th class="text-center">操作</th>
                      </tr>
                      </thead>
                      @foreach($order->items as $index=>$item)
                        <tr>
                          <td class="product-info">
                            <div class="preview">
                              <a href="{{route('products.show',[$item->product_id])}}" target="_blank">
                                <img src="{{$item->product->image_url}}" alt="">
                              </a>
                            </div>
                            <span class="product-title">
                              <a href="{{route('products.show',[$item->product_id])}}" target="_blank">
                                {{$item->product->title}}
                              </a>
                            </span>
                            <span class="sku_title">{{$item->productSku->title}}</span>
                          </td>
                          <td class="sku_price text-center">￥{{$item->price}}</td>
                          <td class="sku_amount text-center">{{$item->amount}}</td>

                          <!--后面的信息是这个订单的信息，一个订单有多个sku就有多行，用rowspan处理-->
                          @if($index ==0)
                            <td rowspan="{{count($order->items)}}" class="text-center total-amount">
                              ￥{{$order->total_amount}}</td>
                            <td rowspan="{{count($order->items)}}" class="text-center ">
                              @if($order->paid_at)
                                <!--REFUND_STATUS_PENDING 未退款-->
                                @if($order->refund_status == \App\Models\Order::REFUND_STATUS_PENDING)
                                  已支付
                                @else
                                  {{\App\Models\Order::$refundStatusMap[$order->refund_status]}}
                                @endif
                              @elseif($order->closed)
                                已关闭
                              @else
                                未支付 <br>
                                请于{{$order->created_at->addSeconds(config('app.order_ttl'))->format('H:i')}}前完成支付
                                <br>否则订单将自动关闭
                              @endif
                            </td>
                            <td rowspan="{{count($order->items)}}" class="text-center ">
                              <a href="{{route('orders.show',['order'=>$order->id])}}" class="btn btn-primary btn-sm">查看订单</a>
                              <!-- 评价入口开始 -->
                              @if($order->paid_at)
                                <a class="btn btn-success btn-sm" href="{{ route('orders.review.show', ['order' => $order->id]) }}">
                                  {{ $order->reviewed ? '查看评价' : '评价' }}
                                </a>
                              @endif
                              <!-- 评价入口结束 -->
                            </td>
                          @endif
                        </tr>
                      @endforeach
                    </table>
                  </div>
                </div>
              </li>
            @endforeach
          </ul>
          <div class="float-right">{{$orders->render()}}</div>
        </div>
      </div>
    </div>
  </div>
@stop
